/*
 * @lc app=leetcode.cn id=150 lang=cpp
 *
 * [150] 逆波兰表达式求值
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <stdlib>
#include <queue>
#include <map>
#include <set>
#include <umordered_map>
#include <umordered_set>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        int sum = 0;
        stack<int> s;
        for(string x : tokens) {
            if(x == "+" || x == "-" || x == "*" || x == "/") {
                int t1 = s.top();
                s.pop();
                int t2 = s.top();
                s.pop();
                if(x == "+") s.push(t1 + t2);
                if(x == "-") s.push(t2 - t1);
                if(x == "*") s.push(t1 * t2);
                if(x == "/") s.push(t2 / t1);
            }else {
                s.push(stoi(x));
            }
        }
        return s.top();
    }
};
// @lc code=end

